package nowCoder;

import java.text.DecimalFormat;

public class Power {
	double Power(double base, int exponent) {
		if(base==0 || base==1)
			return base;
		if(exponent==0)
			return (double)1;
		
		double rst = exponent>0?power(base, exponent):-1* power(base, -1*exponent);
		DecimalFormat dfDecimalFormat = new DecimalFormat("######.00000");
		
		String rstString = dfDecimalFormat.format(rst);
		System.out.println(rstString);
		return Double.parseDouble(rstString);
	}
	
	double power(double base, int exponent){
		if(exponent==1)
			return base;
		else{
			if((exponent & 1) == 0){
				return power(base, exponent>>1) * power(base, exponent>>1);
			} else{
				return power(base, exponent>>1) * power(base, exponent>>1) * base;
			}
		}
	}
	
	public static void main(String[] args){
		Power power = new Power();
		System.out.println(power.Power(2.12345, -2));
	}
}
